import fs from "fs"
import path from "path"

// 清理 console.log 的函数
function cleanConsoleLogs(directory) {
  const files = fs.readdirSync(directory, { withFileTypes: true })

  for (const file of files) {
    const fullPath = path.join(directory, file.name)

    if (file.isDirectory()) {
      cleanConsoleLogs(fullPath)
    } else if (file.name.endsWith(".js") || file.name.endsWith(".vue")) {
      let content = fs.readFileSync(fullPath, "utf8")

      // 移除 console.log 语句
      content = content.replace(/console\.log\([^)]*\);?\s*/g, "")

      // 移除 debugger 语句
      content = content.replace(/debugger;?\s*/g, "")

      fs.writeFileSync(fullPath, content)
      console.log(`已清理: ${fullPath}`)
    }
  }
}

// 执行清理
console.log("开始清理 console.log 语句...")
cleanConsoleLogs("./src")
console.log("清理完成！")
